package web.JavaDate;

import org.junit.jupiter.api.Test;

import java.time.*;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/**
 * description:
 * author:zcx
 * lenovo
 * 时间：2022.02.10.15.28
 */
public class D4 {


    @Test
    public void
    m7(){
        //计算两个日期有多少天
        var d1= LocalDate.now();
        var d2=LocalDate.of(2006,10,20);
        var days=d2.until(d1,ChronoUnit.DAYS);
        //方式一
        System.out.println(days);
        //LocalDateTime
        var du= Duration.between(d2.atStartOfDay(),d1.atStartOfDay());
        //方式二
        System.out.println(du.toDays());
        //方式三
        var days3=ChronoUnit.DAYS.between(d2,d1);
        System.out.println(days3);
    }

    @Test
    public void m6(){
        var n= LocalDateTime.now();
        var f= DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        System.out.println(n.format(f));
        System.out.println(n.getNano());
        //秒
        System.out.println(n.toEpochSecond(ZoneOffset.of("+8")));
        var i=n.toInstant(ZoneOffset.of("+8"));
        //毫秒


    }

}
